package com.original.simuladoresws.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.original.simuladoresws.dao.ProductDao;
import com.original.simuladoresws.entities.TbProduct;

@Repository("productDao")
public class ProductDaoImpl extends GenericDaoImpl<TbProduct> implements ProductDao {

	/*public ProductDaoImpl() {
        super();
    }
	public ProductDaoImpl(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }*/
	@SuppressWarnings("unchecked")
	@Override
	public List<TbProduct> getListActiveProducts() {
		Session session = sessionFactory.openSession();
		List<TbProduct> lsProduct = session.createQuery("FROM TbProduct WHERE esActive = 1").list();
		session.close();
		return lsProduct;
	}

	@SuppressWarnings("unchecked")
	public List<TbProduct> fixedIncomeComparsionsGetList() {
		Session session = sessionFactory.openSession();
		StringBuilder sb = new StringBuilder();
		sb.append("SELECT DISTINCT A FROM TbProduct A ");
		sb.append(" INNER JOIN TbComparsionProduct B ");
		sb.append("		ON A.id = B.id.idComparsion");
		sb.append(" INNER JOIN Comparsion C ");
		sb.append("		ON C.id = B.id.idProduct");
		List<TbProduct> lsProduct = session.createQuery(sb.toString()).list();
		session.close();
		return lsProduct;
		
	}
}
